package com.compass.mobile.ui.activity

import LogUtil
import UserInfoManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import com.compass.mobile.databinding.ActivityPersonalCenteBinding
import com.compass.mobile.framework.base.BaseVBActivity
import com.compass.mobile.framework.constant.CLOUD_FILM_URL
import com.compass.mobile.framework.ext.onClick
import com.compass.mobile.framework.utils.DateUtils
import com.compass.mobile.framework.utils.FocusViewUtils
import com.compass.mobile.ui.viewModel.UserViewModel
import dp2px
import setUrlRound
import toJson

/**
 * Description： 个人中心
 * Date:2024/6/19 10:52
 */
class PersonalCenterActivity : BaseVBActivity<ActivityPersonalCenteBinding>() {

    companion object {
        fun start(context: Context) {
            val intent = Intent(context, PersonalCenterActivity::class.java)
            context.startActivity(intent)
        }
    }

    private val userViewModel: UserViewModel by viewModels()

    override fun initView(savedInstanceState: Bundle?) {
        FocusViewUtils.scaleView(mBinding.caseHistory, 0)
        FocusViewUtils.scaleView(mBinding.llPrescription, 0)
        FocusViewUtils.scaleView(mBinding.llHealthFile, 0)
        FocusViewUtils.scaleView(mBinding.llReport, 0)
        FocusViewUtils.scaleView(mBinding.llReportUpload, 0)
        FocusViewUtils.scaleView(mBinding.llMyConsultation, 0)
        FocusViewUtils.scaleView(mBinding.llTest, 0)
        FocusViewUtils.scaleView(mBinding.llNursingOrder, 0)
    }

    override fun initData() {
        userViewModel.getHosConfig()
        UserInfoManager.getPatientInfo()?.let {
            mBinding.avatar.setUrlRound(it.avatar, dp2px(5f))
            mBinding.tvName.text = it.name

            if (it.sex == "1") mBinding.tvSex.text = "性别：男" else mBinding.tvSex.text = "性别：女"
            mBinding.tvAge.text = "年龄：${DateUtils.formatAge2(it.birthday)}"
        }

        LogUtil.d("info===${UserInfoManager.getPatientInfo()?.toJson()}")
        userViewModel.hosFilmLiveData.observe(this) {
            UserInfoManager.putString(CLOUD_FILM_URL,it)
        }

    }

    override fun intListener() {

        mBinding.llReport.onClick {
            //报告查询
            MyReportTypeActivity.start(this)
        }
        mBinding.llMyConsultation.onClick {
            MyOrderActivity.start(this)
        }

        mBinding.caseHistory.onClick {
            //病历
            CaseHistoryRecordActivity.start(this)
        }

        mBinding.llPrescription.onClick {
            //处方记录
            PrescriptionRecordActivity.start(this)
        }

        mBinding.llTest.onClick {
            //检验检查
            MyInspectionActivity.start(this)
        }
        mBinding.llHealthFile.onClick {
            HealthRecordActivity.start(this)

        }
        mBinding.llReportUpload.onClick {
            ReportUploadActivity.start(this)
        }

        mBinding.llNursingOrder.onClick {
            NursingOrderActivity.start(this)
        }


    }
}